import { getMultiLang } from "nc-lightapp-front";
import requestApi from "../requestApi";
export default function buttonClick() {
  let props = this.props;

  return {
    //修改

    ["Edit"]: () => {
      getMultiLang({
        moduleId: 2011,
        domainName: "erm",
        currentLocale: "zh-CN",
        callback: (json) => {
          props.editTable.setStatus(window.presetVar.bodycode, "edit");
          props.button.setButtonsVisible({Save: true, Cancel: true, Edit:false});
        },
      });
    },

    //保存
    ["Save"]: () => {
        let reqData = props.editTable.getAllData(window.presetVar.bodycode);
        const obj = {
          model: reqData,
          pageid: window.presetVar.pagecode
        }
        requestApi.save({
          data: obj,
          success: (data) => {
            if (data && data[window.presetVar.bodycode]) {
              data &&
                data[window.presetVar.bodycode] &&
                props.editTable.setTableData(
                  window.presetVar.bodycode,
                  data[window.presetVar.bodycode]
                );
            }
            props.editTable.cancelEdit(window.presetVar.bodycode);
            props.button.setButtonsVisible({Save: false, Cancel: false, Edit:true});
            this.pubMessage.saveSuccess();
          },
        });
      
    },

    //取消
    ["Cancel"]: () => {
      props.editTable.cancelEdit(window.presetVar.bodycode);
      props.button.setButtonsVisible({Save: false, Cancel: false, Edit:true});

      requestApi.query({
        data: {
          pagecode: window.pagecode,
        },
        success: (data) => {},
      });
    },

    //增行
    ['Add']: () => {
      props.editTable.addRow(window.presetVar.bodycode)
    }
  };
}
